﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MailTool.Utility
{
    public class SessionState
    {
        static readonly string userId = "currentUser";

        static T GetSessionState<T>(string index)
        {
            return (T)HttpContext.Current.Session[index];
        }

        static T GetSessionState<T>(string index, object defaultValue)
        {
            return HttpContext.Current.Session[index] == null ? (T)defaultValue : (T)HttpContext.Current.Session[index];
        }

        static void SetSessionState(string index, object value)
        {
            HttpContext.Current.Session[index] = value;
        }

        public static void ClearSession()
        {
            HttpContext.Current.Session.Clear();
            // HttpContext.Current.Session.Abandon();
        }

        public static MailModel.User CurrentUser
        {
            get { return GetSessionState<MailModel.User>(userId, new MailModel.User()); }
            set { SetSessionState(userId, value); }
        }
    }
}